#include "tabulationtemplate.h"
#include "domaindetailinfodlg.h"
//#include <QHeaderView>
//#include <QMessageBox>
//#include <QThread>
//#include <QInputDialog>
#include "clientsocket.h"
#include "tdomain.h"
#include "global.h"

TabulationTemplate::TabulationTemplate(QWidget *parent)
    : QWidget{parent}
{
    initUi();

    //m_tDomain = static_cast<TDomain *>(parent);
    //m_tDomain = (TDomain *)parent;
    //HaloKpy *widget =(HaloKpy *)parent; ;
    m_tDomain = static_cast<TDomain *>(QWidget::parentWidget());

    // 初始化域名详情模型
    m_tableModel = new QStandardItemModel;

    m_tableModel->setHorizontalHeaderLabels({"id","categoryId","Domain", "DomainID", "WHOISServer","RegistrarURL","UpdatedDate","CreationDate","ExpiryDate","Registrar","IANAID","AbuseContactEmail","AbuseContactPhone","RegistrantID","RegistrantName","Organization","Street","City","State","PostalCode","Country","Phone","Fax","Email"});
    m_tableView->horizontalHeader()->setStyleSheet("QHeaderView::section { background-color:  rgb(220,220,220);  }");
    m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);//行选中
    m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);//不可编辑
   // m_tableView->horizontalHeader()->setStyleSheet("QHeaderView::section {/*background-color:#1E90FF;*/font:10pt '微软雅黑';}");//标题栏样式
    m_tableView->horizontalHeader()->setFixedHeight(35);//标题栏行高
    m_tableView->verticalHeader()->setDefaultSectionSize(25);//设置列的行高
    m_tableView->setModel(m_tableModel);
    m_tableView->setColumnHidden(0,true);
    m_tableView->setColumnHidden(1,true);

    createDomainInfoRightPopMenu();
    connect(m_pageBar, &QPageBar::pageChanged, this, [&](int idx) {showDomainInfoToTableViewByPage(-1,idx);});
}

TabulationTemplate::~TabulationTemplate()
{

}

void TabulationTemplate::initUi()
{
/*-----------------设置查询区--------------------*/
    m_filterWidget = new QWidget(this);
    m_hFilterLayout = new QHBoxLayout();

    m_lableEdit = new QLabel(this);
    m_lableEdit->setText("请输入");
    m_lableEdit->setMaximumHeight(40);
    m_lableEdit->setAlignment(Qt::AlignCenter);
    m_hFilterLayout->addWidget(m_lableEdit,1);

    m_editText = new QLineEdit(this);
    m_hFilterLayout->addWidget(m_editText,2);

    m_labelComb = new QLabel(this);
    m_labelComb->setText("请选择");
    m_labelComb->setMaximumHeight(40);
    m_labelComb->setAlignment(Qt::AlignCenter);
    m_hFilterLayout->addWidget(m_labelComb,1);

    m_combSelect = new QComboBox(this);
    m_hFilterLayout->addWidget(m_combSelect,2);

    m_labelStart = new QLabel(this);
    m_labelStart->setText("开始日期");
    m_labelStart->setMaximumHeight(40);
    m_labelStart->setAlignment(Qt::AlignCenter);
    m_hFilterLayout->addWidget(m_labelStart,1);

    m_dateStart = new QDateEdit(this);
    m_dateStart->setCalendarPopup(true);
    m_hFilterLayout->addWidget(m_dateStart,2);

    m_labelEnd = new QLabel(this);
    m_labelEnd->setText("结束日期");
    m_labelEnd->setMaximumHeight(40);
    m_labelEnd->setAlignment(Qt::AlignCenter);
    m_hFilterLayout->addWidget(m_labelEnd,1);

    m_dateEnd = new QDateEdit(this);
    m_dateEnd->setCalendarPopup(true);
    m_hFilterLayout->addWidget(m_dateEnd,2);

    m_btnQry = new QPushButton(this);
    m_btnQry->setText("查询");
    m_hFilterLayout->addWidget(m_btnQry,1);

    m_btnReset = new QPushButton(this);
    m_btnReset->setText("重置");
    m_hFilterLayout->addWidget(m_btnReset,1);

    m_btnQry->setEnabled(false);
    m_btnReset->setEnabled(false);

    m_filterSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
    m_hFilterLayout->addSpacerItem(m_filterSpacer);

    m_hFilterLayout->setContentsMargins(0,0,0,0);
    m_hFilterLayout->setStretch(10,4);


    m_filterWidget->setMaximumHeight(40);
    m_filterWidget->setLayout(m_hFilterLayout);
    //m_filterWidget->setStyleSheet("background-color: blue");
    //m_filterWidget->setStyleSheet("border: 1px solid grey");
/*----------------设置操作区域----------------------------------*/
    m_actWidget = new QWidget(this);
    m_hActLayout = new QHBoxLayout();

    m_btnAdd = new QPushButton(this);
    m_btnAdd->setText("增加");
    m_hActLayout->addWidget(m_btnAdd,1);

    m_btnDel = new QPushButton(this);
    m_btnDel->setText("删除");
    m_hActLayout->addWidget(m_btnDel,1);

    m_btnMod = new QPushButton(this);
    m_btnMod->setText("修改");
    m_hActLayout->addWidget(m_btnMod,1);

    m_btnExp = new QPushButton(this);
    m_btnExp->setText("导出");
    m_hActLayout->addWidget(m_btnExp,1);

    m_btnAdd->setEnabled(false);
    m_btnDel->setEnabled(false);
    m_btnMod->setEnabled(false);
    m_btnExp->setEnabled(false);

    m_actSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
    m_hActLayout->addSpacerItem(m_actSpacer);

    m_hActLayout->setContentsMargins(0,0,0,0);
    m_hActLayout->setStretch(4,10);
    m_hActLayout->setSpacing(10);

    m_actWidget->setLayout(m_hActLayout);

    //m_actWidget->setStyleSheet("background-color: red");
    //m_actWidget->setStyleSheet("border: 1px solid grey");
    m_actWidget->setMaximumHeight(40);
/*------------------设置显示区域--------------------------------------------*/
    m_showWidget = new QWidget(this);
    m_vShowLayout = new QVBoxLayout;

    m_tableView = new QTableView(this);
    m_vShowLayout->addWidget(m_tableView,10);

    m_pageBar = new QPageBar(this);
    m_pageBar->m_pageRecCount = 15;
    m_vShowLayout->addWidget(m_pageBar,1);
    m_vShowLayout->setContentsMargins(0,0,0,0);

    m_showWidget->setLayout(m_vShowLayout);
    //m_showWidget->setStyleSheet("background-color: yellow");
    //m_showWidget->setStyleSheet("border: 1px solid grey");
/*----------------设置整体布局----------------------------------*/
    m_vLayout  = new QVBoxLayout;

    m_vLayout->addWidget(m_filterWidget,1);
    m_vLayout->addWidget(m_actWidget,1);
    m_vLayout->addWidget(m_showWidget,8);
    m_vLayout->setContentsMargins(0,0,0,0);
    this->setLayout(m_vLayout);
    setStyleSheet("background-color: #F5F5F5");

}

void TabulationTemplate::createDomainInfoRightPopMenu()
{
    m_domainInfoMenu = new QMenu(this);
    m_addDomainsMenu = new QMenu(this);

    QString menuStyle = "QMenu::item {""color: black; /* 设置菜单项文字颜色 */""}"
                        "QMenu::item:selected {""background-color: #87CEEB; /* 设置被选中菜单项的背景色 */""}"
                        "QMenu::separator {""height: 1px; /* 可选：设置分隔线高度 */""background-color: #777; /* 可选：设置分隔线颜色 */""}";

    //"QMenu {""background-color: #FFF5EE; /* 设置菜单整体背景色 */""}"

    m_domainInfoMenu->setStyleSheet(menuStyle);
    m_addDomainsMenu->setStyleSheet(menuStyle);

    QAction* textImport = m_addDomainsMenu->addAction("文本导入");
    textImport->setIcon(QIcon(":Resource/icon/save-one.svg"));
    connect(textImport, &QAction::triggered, this, &TabulationTemplate::onTextImpDomainRecs);

    QAction* ruleCreate = m_addDomainsMenu->addAction("规则生成");
    ruleCreate->setIcon(QIcon(":Resource/icon/rss.svg"));
    connect(ruleCreate, &QAction::triggered, this, &TabulationTemplate::onRuleCreateDomainRecs);

    QAction* addDomains = m_domainInfoMenu->addAction("添加域名");
    addDomains->setIcon(QIcon(":Resource/icon/tag-one.svg"));
    addDomains->setMenu(m_addDomainsMenu);

    QAction *delDomainsInfo = m_domainInfoMenu->addAction("删除当前域名");
    delDomainsInfo->setIcon(QIcon(":Resource/icon/system.svg"));
    connect(delDomainsInfo, &QAction::triggered, this, &TabulationTemplate::onDelCurrentRec);

    QAction *refDomainsInfo = m_domainInfoMenu->addAction("刷新");
    refDomainsInfo->setIcon(QIcon(":Resource/icon/equalizer.svg"));
    connect(refDomainsInfo, &QAction::triggered, this, &TabulationTemplate::onRefleshDomainTable);

    QAction *qryWhois = m_domainInfoMenu->addAction("查询Whois");
    qryWhois->setIcon(QIcon(":Resource/icon/setting-one.svg"));
    connect(qryWhois, &QAction::triggered, this, &TabulationTemplate::onQryDomainWhois);

    QAction *qryDns = m_domainInfoMenu->addAction("查询DNS");
    qryDns->setIcon(QIcon(":Resource/icon/home.svg"));
    connect(qryDns, &QAction::triggered, this, &TabulationTemplate::onQryDomainDns);

    QAction *qryNetServer = m_domainInfoMenu->addAction("查询网络服务信息");
    qryNetServer->setIcon(QIcon(":Resource/icon/lightning.svg"));
    connect(qryNetServer, &QAction::triggered, this, &TabulationTemplate::onQryDomainNetServer);

    QAction *qryPrice = m_domainInfoMenu->addAction("查询价格");
    qryPrice->setIcon(QIcon(":Resource/icon/loading.svg"));
    connect(qryPrice, &QAction::triggered, this, &TabulationTemplate::onQryDomainPrice);

    // 关键在于在这里处理右键点击事件并显示菜单
    m_tableView->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(m_tableView,SIGNAL(customContextMenuRequested(const QPoint &)),this, SLOT(slotDomainInfoPopMenu(const QPoint &)));
    connect(m_tableView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotRowDoubleClicked(const QModelIndex &)));

}
void TabulationTemplate::slotDomainInfoPopMenu(const QPoint &point)                     //槽函数定义
{
    //m_domainInfoMenu->exec(QCursor::pos());
    m_domainInfoMenu->popup(m_tableView->viewport()->mapToGlobal(point));
}

void TabulationTemplate::slotRowDoubleClicked(const QModelIndex index)
{
    QModelIndex selectedIndex = m_tableView->selectionModel()->currentIndex();
    if (!selectedIndex.isValid()) {
        return;
    }

    QStandardItem *itemId = m_tableModel->item(selectedIndex.row(),0);
    int recId = itemId->text().toInt();
    DomainDetailInfo ddi = getDomainDetailInfoById(recId);

    QSize mainWindowSize = this->m_tDomain->size();
    QSize dialogSize = QSize(mainWindowSize.width() * 0.8, mainWindowSize.height() * 0.8);
    DomainDetailInfoDlg dlg;
    // 设置对话框的大小
    dlg.setFixedSize(dialogSize);

    // 居中显示对话框
    QRect screenGeometry = this->m_tDomain->geometry();
    QPoint centerPos = screenGeometry.center() - QPoint(dialogSize.width() / 2, dialogSize.height() / 2);
    dlg.move(centerPos);
    dlg.initDlgData(ddi);
    dlg.exec();
}

bool TabulationTemplate::matchWhoisServerInfo(QString domainStr,QString &addrStr, int &port)
{
    QString suffix = domainStr.section('.',1,-1);
    QStringList strWhois = g_dnSuffixMappingWhoIs["."+suffix];
    if(strWhois.size()==0)
    {
        qDebug()<<"无法查找到匹配的域名服务器!"<<domainStr;
        return false;
    }
    addrStr = strWhois.at(0);
    port = strWhois.at(1).toInt();
    return true;

//    QStringList domainStrings = domainStr.split(".");
//    QString suffix = domainStrings.at(domainStrings.size()-1);
//    QString str;
//    qDebug()<<suffix;

//    for(int i=0;i<m_tDomain->m_suffixQryAddr.size();i++)
//    {
//        str=m_tDomain->m_suffixQryAddr.at(i).domainSuffix;
//        qDebug()<<str;
//        if(suffix==str)
//        {
//            addrStr=m_tDomain->m_suffixQryAddr.at(i).qryAddress;
//            port=m_tDomain->m_suffixQryAddr.at(i).port;
//            qDebug()<<addrStr<<port;
//            return true;
//        }
//    }
//    return false;
}

DomainDetailInfo TabulationTemplate::getDomainDetailInfoById(int domainId)
{
    DomainDetailInfo ddi;
    ddi.domainId = domainId;

    ddi.domainRegistry = m_tDomain->m_dbMySql->getDomainRegistryById(domainId);
    ddi.domainAdmin= m_tDomain->m_dbMySql->getDomainAdminById(domainId);
    ddi.domainTech = m_tDomain->m_dbMySql->getDomainTechById(domainId);
    ddi.domainBill = m_tDomain->m_dbMySql->getDomainBillById(domainId);
    ddi.domainStatus = m_tDomain->m_dbMySql->getDomainStatusById(domainId);
    ddi.domainNameServer = m_tDomain->m_dbMySql->getDomainNameServerById(domainId);
    return ddi;
}

void TabulationTemplate::clientSocketRequest(QString sendMsg, QString ipAddr, int port)
{
    qDebug()<<"客户端发送查询请求"<<ipAddr<<port<<sendMsg;

    ClientSocket *clientSocket = new ClientSocket();
    clientSocket->m_sendMsg = sendMsg;
    QThread *socketThread = new QThread;

    clientSocket->moveToThread(socketThread);

    connect(socketThread, &QThread::started, clientSocket, [=](){clientSocket->startConnection(ipAddr,port);});
    connect(socketThread, &QThread::finished, socketThread, &QThread::deleteLater);
    connect(socketThread, &QThread::finished, clientSocket, &QObject::deleteLater);

    connect(clientSocket, &QObject::destroyed, socketThread, &QThread::quit);
   // connect(clientSocket, &ClientSocket::socketError, this, [](QAbstractSocket::SocketError error) { /* 错误处理 */ });

    connect(clientSocket, &ClientSocket::dataReceived, this, &TabulationTemplate::dealRecvDataFromServer);
    socketThread->start();

}

void TabulationTemplate::onQryDomainWhois()
{
    QModelIndex selectedIndex = m_tableView->selectionModel()->currentIndex();
    if (!selectedIndex.isValid()) {
        QMessageBox::warning(this, "警告", "请选择一条记录删除！");
        return;
    }

    QStandardItem *itemId = m_tableModel->item(selectedIndex.row(),0);
    int recId = itemId->text().toInt();

    QStandardItem *itemName = m_tableModel->item(selectedIndex.row(),2);
    QString domainStr = itemName->text();
    qDebug()<<"查询域名的whois信息"<<recId<<domainStr;

    QString whoisserver;
    int port;
    if(!matchWhoisServerInfo(domainStr,whoisserver,port))
    {
        qDebug()<<"获取whois服务失败"<<port<<whoisserver;
            return;
    }
    clientSocketRequest("domain "+domainStr,whoisserver,port);
}

void TabulationTemplate::dealRecvDataFromServer( QByteArray data,QString flag)
{
    QModelIndex selectedIndex = m_tableView->selectionModel()->currentIndex();
    if (!selectedIndex.isValid()) {
            QMessageBox::warning(this, "警告", "请选择一条记录删除！");
            return;
    }

    QStandardItem *itemId = m_tableModel->item(selectedIndex.row(),0);
    int domainId = itemId->text().toInt();

    QStandardItem *CId = m_tableModel->item(selectedIndex.row(),1);
    int categoryId = CId->text().toInt();

    QStandardItem *itemName = m_tableModel->item(selectedIndex.row(),2);
    QString domainStr = itemName->text();

    QString strtemp = data;

    qDebug() << "收到服务端数据" << strtemp.length()<<strtemp;
    QStringList domainStrings = strtemp.split("\r\n");
    QMap<QString, QString> infoMaps;
    QVector<QString> statusVectors, nameServerVectors;
    QString keystr, valstr;
    for (int i = 0; i < domainStrings.size(); i++) {
        //qDebug()<<domainStrings.at(i);
        QStringList infoStrings = domainStrings.at(i).split(": ");
        if(infoStrings.size()<2)
        {
            qDebug() << "接收数据异常: " << domainStrings.at(i);
            return;
        }
        keystr = infoStrings.at(0).trimmed();
        valstr = infoStrings.at(1).left(127);
        if(valstr=="REDACTED FOR PRIVACY"||valstr.contains("Please query the WHOIS"))
            valstr="";
        //qDebug()<<keystr<<valstr;
        if (keystr == "Domain Status") {
            statusVectors.append(valstr);
        } else if (keystr == "Name Server") {
            nameServerVectors.append(valstr);
        } else {
            infoMaps[keystr] = valstr;
        }
        //qDebug() << infoStrings.at(0) << infoStrings.at(1);
        if (keystr.trimmed() == "DNSSEC")
            break;
    }
    qDebug() << "解析后，获取信息数据数量" << infoMaps.size();

    m_tDomain->m_dbMySql->updateDomainRegistryById(domainId, domainStr, infoMaps);
    m_tDomain->m_dbMySql->updateDomainAdminById(domainId, domainStr, infoMaps);
    m_tDomain->m_dbMySql->updateDomainTechById(domainId, domainStr, infoMaps);
    m_tDomain->m_dbMySql->updateDomainBillById(domainId, domainStr, infoMaps);
    m_tDomain->m_dbMySql->insertDomainStatus(domainId, domainStr, statusVectors);
    m_tDomain->m_dbMySql->insertDomainNameServer(domainId, domainStr, nameServerVectors);

    onRefleshDomainTable(categoryId);
}


void TabulationTemplate::onQryDomainDns()
{

    QMessageBox::warning(this, "提示", "暂未实现！");
}

void TabulationTemplate::onQryDomainNetServer()
{

    QMessageBox::warning(this, "提示", "暂未实现！");
}

void TabulationTemplate::onQryDomainPrice()
{

    QMessageBox::warning(this, "提示", "暂未实现！");
}

void TabulationTemplate::onTextImpDomainRecs()
{

    QModelIndex selectedIndex = m_tDomain->m_treeView->selectionModel()->currentIndex();
    if (!selectedIndex.isValid()) {
        QMessageBox::warning(this, "警告", "请选择一个节点域名类别！");
        return;
    }
    QStandardItem *selectItem = m_tDomain->m_domainCategoryModel->itemFromIndex(selectedIndex);
    if(selectItem->hasChildren()){
        QMessageBox::warning(this, "警告", "请选择一个叶节点域名类别！");
        return;
    }

    int categoryId = selectItem->data(Qt::UserRole).toInt();
    QString categoryName =selectItem->text();
    qDebug()<<"导入的类别名称"<<categoryId<<categoryName;
    bool ok;
    QInputDialog InputDlg;

    QSize mSize = this->size();
    QSize dialogSize = QSize(mSize.width() * 0.6, mSize.height() * 0.6);
    qDebug()<<mSize;
    InputDlg.setFixedSize(800,600);

    QString text = InputDlg.getMultiLineText(this, "新增域名类别:"+categoryName,tr("域名列:"), "在这里填写域名信息", &ok);
    if (ok && !text.isEmpty())
    {
        QStringList domainStrings = text.split("\n");
        if(m_tDomain->m_dbMySql->insertDomainRecToTables(categoryId,domainStrings))
            onRefleshDomainTable(categoryId);//刷新
        else
            qDebug()<<"insertDomainInfoRec fail";
    }
}

void TabulationTemplate::onRuleCreateDomainRecs()
{

    QMessageBox::warning(this, "提示", "暂未实现！");
}

void TabulationTemplate::onDelCurrentRec()
{

    QModelIndex selectedIndex = m_tableView->selectionModel()->currentIndex();
    if (!selectedIndex.isValid()) {
        QMessageBox::warning(this, "警告", "请选择一条记录删除！");
        return;
    }

    QStandardItem *itemId = m_tableModel->item(selectedIndex.row(),0);
    int recId = itemId->text().toInt();

    QStandardItem *itemName = m_tableModel->item(selectedIndex.row(),2);

    QString infostr ="是否要删除该记录:"+itemName->text();
    QMessageBox::StandardButton result= QMessageBox::question(this,"提示",infostr);
        if(result==QMessageBox::Yes)
        {
            m_tDomain->m_dbMySql->deleteDomainRecFromTable(recId);
            m_tableModel->removeRow(selectedIndex.row(), selectedIndex.parent());
        }
}

void TabulationTemplate::showDomainInfoToTableViewByPage(int categoryId, int curPage)
{
        //qDebug()<<categoryId<<curPage;
        if(categoryId==-1)
            categoryId = m_categoryId;
        m_pageBar->m_currentPage = curPage;

        //qDebug()<<m_pageBar->m_recTotalCount<<m_pageBar->m_pageTotalCount<<categoryId;
        m_tableModel->removeRows(0, m_tableModel->rowCount()); // 清空表格数据
        QList<DomainInfo> diList = m_tDomain->m_dbMySql->getAllDomainRecByCategoryId(categoryId,curPage,m_pageBar->m_pageRecCount);
        for (const DomainInfo &domainInfo : diList) {
            QList<QStandardItem *> rowItems = createDomainInfoRow(domainInfo);
            m_tableModel->appendRow(rowItems);
        }
        //qDebug() << "刷新该类别的所有域名信息,类别id:" << categoryId << "记录数" << diList.size();
}

void TabulationTemplate::onRefleshDomainTable(int categoryId)
{
    //    qDebug()<<"要刷新此类别的所有域名信息"<<categoryId<<m_categoryId;

    if(categoryId==0)
    {
        QModelIndex selectedIndex = m_tDomain->m_treeView->selectionModel()->currentIndex();
        if (selectedIndex.isValid())
        {
            QStandardItem *tItem = m_tDomain->m_domainCategoryModel->itemFromIndex(selectedIndex);
            m_categoryId = tItem->data(Qt::UserRole).toInt();
        }
    }else
        m_categoryId = categoryId;

    int rectotal = m_tDomain->m_dbMySql->getRecTotalCount("DomainByCategoryId",QString::number(categoryId));
    m_pageBar->m_recTotalCount = rectotal;

    m_pageBar->m_pageTotalCount = (m_pageBar->m_recTotalCount - 1) / m_pageBar->m_pageRecCount + 1;
    if (m_pageBar->m_pageTotalCount >= 3)
        m_pageBar->setCount(m_pageBar->m_pageTotalCount, 3);
    else
        m_pageBar->setCount(m_pageBar->m_pageTotalCount, m_pageBar->m_pageTotalCount);
    //默认显示第一页
    showDomainInfoToTableViewByPage(m_categoryId,1);

}


QList<QStandardItem*> TabulationTemplate::createDomainInfoRow(const DomainInfo &domainInfo)
{
    QList<QStandardItem*> itemList;
    itemList.append(new QStandardItem(QString::number(domainInfo.Id)));
    itemList.append(new QStandardItem(QString::number(domainInfo.CategoryId)));
    itemList.append(new QStandardItem(domainInfo.Domain));
    itemList.append(new QStandardItem(domainInfo.RegistryDomainID));
    itemList.append(new QStandardItem(domainInfo.RegistrarWHOISServer));
    itemList.append(new QStandardItem(domainInfo.RegistrarURL));
    itemList.append(new QStandardItem(domainInfo.UpdatedDate));
    itemList.append(new QStandardItem(domainInfo.CreationDate));
    itemList.append(new QStandardItem(domainInfo.RegistryExpiryDate));
    itemList.append(new QStandardItem(domainInfo.Registrar));
    itemList.append(new QStandardItem(domainInfo.RegistrarIANAID));
    itemList.append(new QStandardItem(domainInfo.RegistrarEmail));
    itemList.append(new QStandardItem(domainInfo.RegistrarPhone));
    itemList.append(new QStandardItem(domainInfo.RegistryRegistrantID));
    itemList.append(new QStandardItem(domainInfo.RegistrantName));
    itemList.append(new QStandardItem(domainInfo.RegistrantOrganization));
    itemList.append(new QStandardItem(domainInfo.RegistrantStreet));
    itemList.append(new QStandardItem(domainInfo.RegistrantCity));
    itemList.append(new QStandardItem(domainInfo.RegistrantStateProvince));
    itemList.append(new QStandardItem(domainInfo.RegistrantPostalCode));
    itemList.append(new QStandardItem(domainInfo.RegistrantCountry));
    itemList.append(new QStandardItem(domainInfo.RegistrantPhone));
    itemList.append(new QStandardItem(domainInfo.RegistrantFax));
    itemList.append(new QStandardItem(domainInfo.RegistrantEmail));
    //qDebug()<<domainInfo.RegistrantStreet<<domainInfo.domain;
    //qDebug()<<domainInfo.id<<domainInfo.domain;
    return itemList;
}
